package org.swan.web.user.controller;

import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import org.stream.base.MessageBean;
import org.swan.web.user.bean.UserExtensionBean;
import org.swan.web.user.service.UserExtensionService;

import java.util.List;

@RestController
@RequestMapping("/user_extension")
public class UserExtensionController {
    private final UserExtensionService userExtensionService;

    public UserExtensionController(UserExtensionService userExtensionService) {
        this.userExtensionService = userExtensionService;
    }

    @GetMapping("/get")
    public MessageBean<UserExtensionBean> get(@RequestParam("userExtensionId") long userExtensionId) {
        return MessageBean.MSG_SUCCESS.setData(userExtensionService.getUserExtensionById(userExtensionId));
    }

    @PostMapping("add")
    public MessageBean<UserExtensionBean> add(@RequestBody UserExtensionBean userExtensionBean) {
        long userExtensionId = userExtensionService.addUserExtension(userExtensionBean);
        return MessageBean.MSG_SUCCESS.setData(userExtensionService.getUserExtensionById(userExtensionBean.getUserExtensionId()));
    }

    @PostMapping("update")
    public MessageBean<UserExtensionBean> update(@RequestBody UserExtensionBean userExtensionBean) {
        return MessageBean.MSG_SUCCESS.setData(userExtensionService.updateUserExtension(userExtensionBean));
    }

    @GetMapping("delete")
    public MessageBean<UserExtensionBean> delete(@RequestParam("userExtensionId") long userExtensionId) {
        return MessageBean.MSG_SUCCESS.setData(userExtensionService.deleteUserExtensionById(userExtensionId));
    }

    @GetMapping("list")
    public MessageBean<List<UserExtensionBean>> list(@Param("offset") int offset, @Param("rows") int rows) {
        return MessageBean.MSG_SUCCESS.setData(userExtensionService.list(offset, rows));
    }
}
